

package com.hazelcast.internal.util.comparators;

import com.hazelcast.internal.serialization.Data;
import com.hazelcast.internal.serialization.SerializationService;

/**
 * Comparator for {@link com.hazelcast.config.InMemoryFormat#BINARY} backed
 * data structures.
 */
final class BinaryValueComparator implements ValueComparator {

    public static final ValueComparator INSTANCE = new BinaryValueComparator();

    private BinaryValueComparator() {
    }

    @Override
    public boolean isEqual(Object value1, Object value2, SerializationService ss) {
        if (value1 == value2) {
            return true;
        }
        if (value1 == null || value2 == null) {
            return false;
        }
        // the PartitioningStrategy is not needed
        // here, since `Data.equals()` only checks
        // the payload, not the partitionHash
        Data data1 = ss.toData(value1);
        Data data2 = ss.toData(value2);
        return data1.equals(data2);
    }
}
